package com.mobile_fault_detector.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mobile_fault_detector.entity.Users;
import com.mobile_fault_detector.mapper.IUserMapper;
import com.mobile_fault_detector.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户服务实现类
 */
@Slf4j
@Service
public class UserServiceImpl implements IUserService {


    private final IUserMapper IUserMapper;

    @Autowired
    public UserServiceImpl(IUserMapper IUserMapper) {
        this.IUserMapper = IUserMapper;
    }


    @Override
    public Users saveUser(Users users) {
        log.info("保存用户信息: {}", users);
        IUserMapper.insert(users);
        return users;
    }

    @Override
    public Users getUserById(Long userId) {
        log.info("根据ID查询用户信息: {}", userId);
        return IUserMapper.selectById(userId);
    }

    @Override
    public Users getUserByPhoneNumber(String phoneNumber) {
        log.info("根据手机号查询用户信息: {}", phoneNumber);
        LambdaQueryWrapper<Users> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Users::getPhoneNumber, phoneNumber);
        return IUserMapper.selectOne(queryWrapper);
    }
}